/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-07-24
 * Time: 19:06
 */
public class Test1 {
    public static Object locker1 = new Object();
    public static Object locker2 = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (locker1) {
                System.out.println("t1加锁");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (locker2) {
                    System.out.println("t2加锁");
                }
                ;
            }
            ;
        });
        Thread t2 = new Thread(() -> {
            synchronized (locker1) {
                System.out.println("t1加锁");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (locker2) {
                    System.out.println("t2加锁");
                }
                ;
            }
            ;
        });
        t1.start();
        t2.start();
    }
}
